<template>
  <div class="container">
    <div class="left">
      <!-- 卡片视图区域 -->
      <el-card>
        <h3>管理员列表</h3>
        <!-- 搜索与添加区域 -->
        <el-row :gutter="20">
          <el-col :span="6">
            <el-input placeholder="请输入搜索内容" v-model="queryInfo.value"
              @keyup.enter.native="getAllAdmins" clearable>
              <el-button slot="append" icon="el-icon-search"
                @click="getAllAdmins"></el-button>
            </el-input>
          </el-col>
        </el-row>

        <!-- 主体 -->
        <el-table :data="adminList" style="width: 100%" border>
          <!-- id -->
          <el-table-column prop="_id" label="id">
          </el-table-column>
          <!-- 用户名 -->
          <el-table-column prop="account" label="用户名" width="100">
          </el-table-column>
          <!-- 真实姓名 -->
          <el-table-column prop="realname" label="真实姓名" width="100">
          </el-table-column>
          <!-- 联系方式 -->
          <el-table-column prop="telephone" label="联系方式" width="200">
          </el-table-column>
          <!-- 操作 -->
          <el-table-column prop="" label="操作" width="100">
            <template slot-scope="scope">
              <!-- 删除 -->
              <el-button size="mini" type="danger" icon="el-icon-delete"
                @click="delAdmins(scope.row._id)">删除</el-button>
            </template>
          </el-table-column>
        </el-table>
        <!-- 分页 -->
        <div class="pages">
          <el-pagination @size-change="" @current-change=""
            :current-page="queryInfo.currentPage" :page-sizes="[1, 2, 5, 10]"
            :page-size="queryInfo.pageSize"
            layout="total, sizes, prev, pager, next, jumper" :total="total">
          </el-pagination>
        </div>
      </el-card>
    </div>
    <div class="right">
      <AdminAdd @getAllAdmins='getAllAdmins' />
    </div>
  </div>
</template>

<script>
import AdminAdd from './add/AdmintAdd.vue'
export default {
  components: { AdminAdd },
  data() {
    return {
      adminList: [],
      changeStudent: {},
      changeNum: 0,
      queryInfo: { pageSize: 5, currentPage: 1, value: "" },
      total: 0,
    };
  },
  computed: {
  },
  methods: {
    // 获取学生列表
    async getAllAdmins() {
      // 发请求
      let { data } = await this.$api.userApi.getAllAdmins({
      });
      this.adminList = data.message
      // console.log(data);
    },
    //删除
    delAdmins(_id) {
      this.$api.userApi.delAdmins({ _id }).then(({ data }) => {
        // 删除提示
        this.$message.success(data.msg);
        this.getAllAdmins();

      });
    }
  },
  created() {
    this.getAllAdmins();
  }
};
</script>

<style lang="scss" scoped>
img {
  width: 50px;
  height: 50px;
}

input {
  width: 100px;
}
.container {
  display: flex;
  .left {
    width: 1000px;
  }
  .right {
    width: 290px;
    margin-left: 20px;
    > div {
      display: flex;
      flex-direction: column;
    }
  }
}
</style>
